
#include "glut_interface.h"
#include "v3d_renderer.h"

GlutInterface::GlutInterface(void)
{
	LOG("hello glut_interface ......\n");

}

GlutInterface::~GlutInterface(void)
{

}


void GlutInterface::Update()
{
	V3dInterface::Update();
}

void GlutInterface::Start()
{
	glutMainLoop();

}
// this function gets called continuously (alternates execution with "Display")
void DoIdle()
{
  glutPostRedisplay();
}

void GlutInterface::InitWindow()
{
	glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA | GLUT_MULTISAMPLE );
	glutInitWindowPosition( 100, 100 );
	glutInitWindowSize( 640, 480 );

	int argc = 1;
	char *argv[40] = {"test"};
	glutInit( &argc, argv );

	glutCreateWindow("simpleogl");

	glutReshapeFunc(glutResize);
	glutDisplayFunc(glutDisplay);
	glutIdleFunc(DoIdle);
	glutKeyboardFunc(EventHandlerKeyPress);
	glutKeyboardUpFunc(EventHandlerKeyUp);



}

void EventHandlerKeyPress (unsigned char key, int x, int y)
{
	LOG("KEY PRESSED %d\n",key);
	IINTERFACE->SetKey(key);
}
void EventHandlerKeyUp (unsigned char key, int x, int y)
{
	LOG("KEY released %d\n",key);
	IINTERFACE->ResetKey(key);
}

//glut functions
void glutResize(int width, int height)
{
	if(RENDERER != NULL)
	{
		RENDERER->Resize(width, height);
	}

}

void glutDisplay(void)
{
	if(RENDERER != NULL)
		RENDERER->Update();

	glutSwapBuffers();

}






